package org.sport.repository;

import org.sport.model.entityModel.UserprivatetableEntity;
import org.sport.model.entityModel.UsertableEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;


@Repository
public interface UserprivateRepository extends JpaRepository<UserprivatetableEntity,Integer> {


    @Transactional
    @Query("select userpri from UserprivatetableEntity userpri where userpri.usertableByUserId.id =?1")
    public UserprivatetableEntity findUserPriByUserId(Integer userId);


    @Modifying
    @Transactional
    @Query("update UserprivatetableEntity uspri set uspri.userName=:qUserName, " +
            "uspri.totWalkDis=:qTotWalkDis, " +
            "uspri.totRunDis=:qTotRunDis, " +
            "uspri.totCycDis=:qTotCycDis, " +
            "uspri.height=:qHeight,"+
            "uspri.weight=:qWeight,"+
            "uspri.bodyFatRate=:qBodyFatRate,"+
            "uspri.totSpoTim=:qTotSpoTim,"+
            "uspri.sex=:qSex"+
            " where uspri.usertableByUserId=:qUserTableByUserId")
    public void updateUserPrivateinfo(@Param("qUserName") String UserName,
                           @Param("qTotWalkDis") Double TotWalkDis,
                           @Param("qTotRunDis") Double TotRunDis,
                           @Param("qTotCycDis") Double TotCycDis,
                           @Param("qHeight") Integer Height,
                           @Param("qWeight") Double Weight,
                           @Param("qBodyFatRate") Double BodyFatRate,
                           @Param("qTotSpoTim") Double TotSpoTim,
                           @Param("qSex") Integer Sex,
                           @Param("qUserTableByUserId") UsertableEntity UsertableByUserId
    );

}
